package org.com.suit.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.com.suit.dao.impl.RegistDaoImpl;
import org.com.suit.domain.Relation;
import org.com.suit.domain.Member;
import org.com.suit.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class RegistDao implements RegistDaoImpl{

	@Autowired
	SqlSession sqlSession;
	
	
	/* 新規ユーザー登録 */ 
	public void addUser(Member user) {

		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		mapper.insertUser(user);
			
	}
	
	/* ユーザー全体目録呼び出し */
	public List<Member> getUserList() {
		List<Member> userList = new ArrayList<Member>();
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		userList = mapper.selectUserList();
		
		return userList;
	}
	
	/* 名前でユーザー検索 */
	public Member findUserByName(String name) {
		Member user = new Member();
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		user = mapper.selectUserByName(name);
		
		return user;
	}
	
	/* get following name */
	public String getUserName(Integer no) {
		String name = null;
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		name = mapper.getUserName(no);
		
		return name;
	}
	
	/* ユーザー情報の返還 */
	public void updateUser(Member user) {
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		mapper.updateUser(user);
				
	}

	/* ユーザー脱退 */
	public void deleteUser(Integer no) {
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		mapper.deleteUser(no);
				
	}
	
	/* follow 追加 */
	public void addFollowing(Relation rel) {

		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		mapper.addFollowing(rel);
				
	}
	
	/* follow 解除 */
	public void cancelFollowing(Integer no) {
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		mapper.cancelFollowing(no);
				
	}

	/* get relation information */
	public List<Relation> getRelationInfo(Integer no) {
		List<Relation> list = new ArrayList<Relation>();
		
		UserMapper mapper = sqlSession.getMapper(UserMapper.class);
		list = mapper.getRelationInfo(no);
		
		return list;
	}
	

}
